Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] feat: allow single pointer drag #53

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

CecoMilchev
Copy link

@CecoMilchev CecoMilchev commented Aug 7, 2023

Related to: #52

cc: @telerik/kendo-dev-leads

@CecoMilchev CecoMilchev requested a review from a team as a code owner August 7, 2023 06:28
@CecoMilchev CecoMilchev marked this pull request as draft August 7, 2023 06:28
@CecoMilchev CecoMilchev marked this pull request as ready for review August 11, 2023 08:29
Comment on lines +5 to +7
cancel?: Function;
mouseOnly?: boolean;
clickMoveClick?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggetions for naming changes are posted in the spec:
#52 (comment)

@@ -15,6 +15,7 @@ const touchRegExp = /touch/;
// 300ms is the usual mouse interval;
// // However, an underpowered mobile device under a heavy load may queue mouse events for a longer period.
const IGNORE_MOUSE_TIMEOUT = 2000;
const ESC = 27;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We better extract this to an enum-like entity like KeyCode:

https://github.com/telerik/blazor/blob/4f624d14e1ed064dc0ce769b154f258667beb769/js/telerik-blazor/src/common/navigation/keys.ts#L6

Other keys can be added to this enum and it can be reused.

@@ -92,12 +96,31 @@ export class Draggable {
const { which } = e;

if ((which && which > 1) || this._ignoreMouse) {
bind(this.document, "contextmenu", preventDefault);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We better add a comment on why this is necessary (e.g. add info that we need the right mouse button for canceling the drag action).

It is also worth it to consider if there is a very very specific case if you stop dragging on something, but expect to open the context menu, e.g. if customers have added a ContextMenu component and expect it to be opened.

@@ -92,12 +96,31 @@ export class Draggable {
const { which } = e;

if ((which && which > 1) || this._ignoreMouse) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +101 to +103
this.cancelDrag(e);

this._cancelHandler(e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we better reverse the order and act depending on whether the dragCancel event is prevented or not - consider the scenario where consumers of the package are notified for the dragCancel event, but they prevent it - then the dragCancel event should allow not cancelling the dragCancel event, thus the cancelDrag function should not be executed.

The above is only true if we actually want to allow preventing events, which I don't think is currently supported in the kendo-draggable package. Still, it is still valid to think if reversing the order is better as we notify for the occurrence of the dragCancel and then we actually cancel it. It will also help if we introduce something like dragCancelEventArgs.preventDefault someday.

Comment on lines +193 to +196
if (e.keyCode === ESC) {
this.cancelDrag(e);
this._cancelHandler(e);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this behavior can be an option - navigable: true.

We discussed this offline - some suites like Kendo Angular/React might want to have their own events or specific navigation and want to cancel the drag on Escape optionally.

unbind(this.document, "contextmenu", preventDefault);
}

this._isDragging = !this._isDragging;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this._isDragging = !this._isDragging;
this._isDragging = false;

if (!this._clickMoveClick) {
bind(this.document, "mouseup", this._mouseup);
bind(this.document, "mousemove", this._mousemove);
bind(this.document, "contextmenu", preventDefault);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event wasn't prevented in the original version (and will prevent the "contextmenu", which might be interpreted as a regression) - it seems better not to have it here, but only when the lick-move-click dragging option is enabled. Am I missing something?

Comment on lines +114 to +117
if (this._isDragging) {
bind(this.document, "mouseup", this._mouseup);
} else {
bind(this.document, "mousemove", this._mousemove);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a comment about why isDragging can be true here - in the general case, it is not possible for the "start" event to be triggered after a "move" action has taken place, but we want exactly this here, so an explanation would be helpful.

Comment on lines +146 to +158
bind(this.document, "pointerup", this._pointerup);
bind(this.document, "pointercancel", this._pointerup);
bind(this.document, "contextmenu", preventDefault);
bind(this.document, "pointermove", this._pointermove);
this._pressHandler(e);
} else {
if (this._isDragging) {
bind(this.document, "pointerup", this._pointerup);
bind(this.document, "pointercancel", this._pointerup);
} else {
bind(this.document, "pointermove", this._pointermove);
bind(this.document, "keydown", this._keydown);
this._pressHandler(e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it is easy for us to attach more than 1 event handler here for the same event as we have some logic for binding and unbinding events.

As we do not want to have more than 1 handler - what about unbinding the event in the bind function and re-attaching it? This should save us from potential duplications - it would have been nice if we can check if the event has been attached already, but this will require more code.

@CecoMilchev CecoMilchev changed the title feat: allow single pointer drag [DO NOT MERGE] feat: allow single pointer drag Aug 17, 2023
@CecoMilchev CecoMilchev marked this pull request as draft August 17, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants